import DictOptions from '@/utils/dict/DictOptions.ts'

export default class DictMeta {
  public type: string
  public request: () => any
  public parse: () => any
  public responseConverter: () => any
  public labelField: string[]
  public valueField: string[]

  /*构造方法*/
  constructor(options: any) {
    this.type = options.type
    this.request = options.request
    this.responseConverter = options.responseConverter
    this.labelField = options.labelField
    this.valueField = options.valueField
  }
}

DictMeta.parse = function (options) {
  console.log('DictMeta.parse方法执行')
  let opts = null

  /*判断options是否为string类型，是的话直接进行赋值*/
  if (typeof options === 'string') {
    /*将DictOptions中的metas*的这个键进行取出*/
    opts = DictOptions.metas['*']
    opts.type = options
  }
  /*返回的是一个DictMeta的类*/
  return new DictMeta(opts)
}
